package cn.jdy.plugins.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.entity.OrderRecord;


/**
 * @title 直播支付记录(打赏和不免费直播支付记录)后台操作
 * @author jga
 * @since 1-12-2015
 */
@Service
public class OrderRecordService extends BaseDao<OrderRecord>{
	/**
	 * 按条件查询
	 * @param sp
	 * 
	 * @return
	 */
	public List<OrderRecord> query(OrderRecord sp){
		if(sp==null) return super.findAll();
		if(sp.getiDisplayLength() > 0){
	     return super.find(createFilter(sp),sp.getiDisplayStart(),sp.getiDisplayLength());
			}
		return super.find(createFilter(sp));
	}
	 public List<OrderRecord> querypage(OrderRecord sp){
	       return super.find(createFilter(sp),sp.getPageNo(),18);
	  }
	public Long count(OrderRecord sp){
		return super.count(createFilter(sp));
	}
	/**
	 * 拼装条件
	 * @param sp
	 * 
	 * @return
	 */
	private DetachedCriteria createFilter(OrderRecord sp){
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	
	 
	  
    if(!StringUtil.isNullOrEmpty(sp.getCreateTime())&&!",".equals(sp.getCreateTime())) {
   
        if( sp.getCreateTime().split(",").length>1){
          dc.add(Restrictions.between("createTime", sp.getCreateTime().split(",")[0], sp.getCreateTime().split(",")[1]));
        }else{
          dc.add(Restrictions.like("createTime", sp.getCreateTime(),MatchMode.ANYWHERE));
        }
     
    }

		dc.addOrder(Order.desc("createTime"));
			return dc;
	}
	
}
